//
//  myCollectionViewController.m
//  iNews
//
//  Created by lanou3g on 14-12-15.
//  Copyright (c) 2014年 张在青. All rights reserved.
//

#import "myCollectionViewController.h"
#import "mycollectionView.h"
#import "arcticViewController.h"
#import "pictureViewController.h"
#import "arcticView.h"
#import "pictureView.h"

#import "DetailModel.h"
#import "ArchiveHandleSingle.h"

@interface myCollectionViewController ()
{
    UITableViewCellEditingStyle _style;
    BOOL _flag;
}

@property(nonatomic,retain)mycollectionView *mycollect;


@end

@implementation myCollectionViewController

- (void)dealloc
{
    [_mycollect release];
    
    [super dealloc];
    
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
       
        self.mycollect = [[[mycollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
  
        self.title = @"我的收藏";
    }
    return self;
}


-(void)loadView{

    self.view = self.mycollect;
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    

    //添加子controller
    
    self.picVC = [[[pictureViewController alloc] init]
                  autorelease];
    [self addChildViewController:self.picVC];
    
    [self.mycollect addSubview:self.picVC.view];
    
    
 self.arctVC= [[[arcticViewController alloc] init] autorelease];

    [self addChildViewController:self.arctVC];
    [self.mycollect addSubview:self.arctVC.view];
    
    //给segment 添加方法
    [self.mycollect.segment addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:@selector(editCell:)];
    
}

//segment事件
-(void)segAction:(UISegmentedControl *)sender{

    
    if (sender.selectedSegmentIndex == 0) {
        [self.mycollect bringSubviewToFront:self.arctVC.view];
    }else{
    
        [self.mycollect bringSubviewToFront:self.picVC.view];
    }


}

//编辑事件
//1.打开编辑状态
- (void)editCell:(UIBarButtonItem *)sender
{
    _style = UITableViewCellEditingStyleDelete;
    
    self.arctVC.artStyle = _style;
    self.picVC.picStyle = _style;
    
    _flag = self.picVC.pic.pctureTab.editing;
    [self.picVC.pic.pctureTab setEditing:!_flag animated:YES];
    [self.arctVC.arctic.arcticTab setEditing:!_flag animated:YES];
    
    if (_flag) {
        [self.navigationItem.rightBarButtonItem setTitle:@"编辑"];
    }else{
        
        [self.navigationItem.rightBarButtonItem setTitle:@"完成"];
    }
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
